package cn.itcast.bos.web.action.system;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.domain.system.Role;
import cn.itcast.bos.service.system.RoleService;
import cn.itcast.bos.web.action.common.BaseAction;

public class RoleAction extends BaseAction<Role> {
	@Resource
	private RoleService service;

	@Action(value = "role_list", results = { @Result(name = "success", type = "json") })
	public String role_list() {
		List<Role> list = service.findAll();
		ActionContext.getContext().getValueStack().push(list);
		return SUCCESS;
	}

	// 属性驱动
	private String[] permissionIds;
	private String menuIds; // ，分隔

	public void setPermissionIds(String[] permissionIds) {
		this.permissionIds = permissionIds;
	}

	public void setMenuIds(String menuIds) {
		this.menuIds = menuIds;
	}

	@Action(value = "role_save", results = {
			@Result(name = "success", type = "redirect", location = "pages/system/role.html") })
	public String role_save() {
		service.saveRole(model,permissionIds,menuIds);
		return SUCCESS;
	}
}
